package com.kt.delivery.config;

import java.io.Serializable;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Random;

/**
 * @ClassName IdGen
 * @Description TODO
 * @Author ghs
 * @Date 2024-04-02 23:19
 * @Version 1.0
 */
public class IdGen implements Serializable {

    /**
     * 生成订单id
     * @return
     */
    public static String getUuid(){
        // 生成一个指定范围内的随机整数，例如[0, 100)
        int min = 0;
        int max = 1000000000;
        // 创建一个Random对象
        Random random = new Random();
        int randomIntInRange = random.nextInt(max - min + 1) + min;

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = simpleDateFormat.format(date);
        String orderId = randomIntInRange+format;

        return orderId;
    }

    private static final String ALLOWED_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    /**
     * 生成商户订单号
     * @return
     */
    public static String generateMerchantOrderNumber() {

        StringBuilder sb = new StringBuilder(18);
        SecureRandom random = new SecureRandom();
        for (int i = 0; i < 18; i++) {
            int randomIndex = random.nextInt(ALLOWED_CHARACTERS.length());
            char randomChar = ALLOWED_CHARACTERS.charAt(randomIndex);
            sb.append(randomChar);
        }
        return sb.toString();
    }

    /**
     * 生成随机32位随机数
     * @return
     */
    public static String getNoStr(){
        return new Random().toString().replace("-","").substring(0,32);
    }
}
